<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>名单列表</legend>
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </fieldset>
    </div>
    <script type="text/html" id="currentTableBar">
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
    </script>
</div>
</div>

<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'tree', 'util', 'layer'], function () {
        let $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            tree = layui.tree,
            layer = layui.layer,
            util = layui.util;


        table.render({
            elem: '#currentTableId',
            url: '/api/table.json',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    {type: "checkbox", width: 50, fixed: "left"},
                    {field: 'name', width: 80, title: '姓名'},
                    {field: 'idCard', width: 120, title: '证件号'},
                    {field: 'sex', width: 120, title: '韦根号', sort: true},
                    {field: 'city', width: 80, title: '角色'},
                    {field: 'sign', title: '部门', Width: 80},
                    {field: 'experience', width: 120, title: '备注'},
                    {field: 'score', width: 80, title: '图像'},
                    {title: '操作', minWidth: 50, toolbar: '#currentTableBar', fixed: "right", align: "center"}
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            let result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            let data = obj.data;
            if (obj.event === 'edit') {

                let index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: './addAndEdit.html?id=' + data.id + '', //通过id找到要编辑的人
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            }
        });
    });
</script>
</body>
</html>